define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'data/shoptotaldata/index' + location.search,
                    add_url: 'data/shoptotaldata/add',
                    edit_url: 'data/shoptotaldata/edit',
                    del_url: 'data/shoptotaldata/del',
                    multi_url: 'data/shoptotaldata/multi',
                    import_url: 'data/shoptotaldata/import',
                    table: 'shop_day_trade',
                }
            });

            var table = $("#table");

            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#one_t").text(data.extend.one);
                $("#two_t").text(data.extend.two);
                $("#three_t").text(data.extend.three);

            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'shop_id', title: __('店铺ID')},
                        // {field: 'org_id', title: __('Org_id')},
                        {field: 'shop_name', title: __('店铺名称'), operate: 'LIKE',align:'left'},
                        {
                            field: 'create_time',
                            title: __('统计时间'),
                            visible: false,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {field: 'total_amount', title: __('总流水'), operate: false, sortable: true},
                        {field: 'book_amount', title: __('包厢预约'), operate: false, sortable: true},
                        {field: 'tq_amount', title: __('台球流水'), operate: false, sortable: true},
                        {field: 'book_pay_amount', title: __('预约实付'), operate: false, sortable: true},
                        {field: 'charge_amount', title: __('充值金额'), operate: false, sortable: true},
                        {field: 'tuan_amount', title: __('团购券购买'), operate: false, sortable: true},
                        {field: 'dou_amount', title: __('抖音核销'), operate: false, sortable: true},
                        {field: 'mt_amount', title: __('美团核销'), operate: false, sortable: true},

                        {field: 'refund_amount', title: __('退款金'), operate: false},
                        {field: 'balance_amount', title: __('余额抵扣'), operate: false, sortable: true},
                        {field: 'order_tuan', title: __('团购券抵扣'), operate: false},
                        {field: 'profit', title: __('收益'), operate: false},
                        {field: 'tq_pay_amount', title: __('台球实付'), operate: false},
                        // {
                        //     field: 'shop.open_date',
                        //     title: __('开业日期'),
                        //     operate: false,
                        //     formatter: Table.api.formatter.datetime
                        // },
                        // {
                        //     field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        //     buttons: [],
                        //     formatter: function (value, row, index) {
                        //         var that = $.extend({}, this);
                        //         var table = $(that.table).clone(true);
                        //         $(table).data("operate-edit", null);
                        //         $(table).data("operate-del", null);
                        //
                        //         that.table = table;
                        //         return Table.api.formatter.operate.call(that, value, row, index);
                        //     }
                        // }
                    ]
                ]
            });

            //展示平台收益明细
            // $(document).on("click", ".platform_btn", function () {
            //     var shop_name = $('#shop_name').val();
            //     var time = $('#create_time').val();
            //     console.log('获取的时间值为：' + time);
            //     Fast.api.open('data/shoptotaldata/show1?time=' + time + '&shop_name=' + shop_name, '平台收益明细', {
            //         area: ['50%', '65%'], // 自定义宽度和高度
            //     });
            // });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
